package com.sg.business.commons.ui.page;

import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.forms.IManagedForm;

import com.mobnut.db.model.IPrimaryObjectValueChangeListener;
import com.mobnut.db.model.PrimaryObject;
import com.sg.business.model.INoticeProvider;
import com.sg.business.model.WorkEventNoticeTemplate;
import com.sg.widgets.part.editor.PrimaryObjectEditorInput;
import com.sg.widgets.part.editor.page.AbstractFormPageDelegator;
import com.sg.widgets.registry.config.BasicPageConfigurator;

public class WorkEventNoticeSettingPage extends AbstractFormPageDelegator
		implements IPrimaryObjectValueChangeListener {

	private WorkEventNoticeSettingPanel esp;
	private INoticeProvider data;

	@Override
	public Composite createPageContent(IManagedForm mForm, Composite parent,
			PrimaryObjectEditorInput input, BasicPageConfigurator conf) {
		super.createPageContent(mForm, parent, input, conf);
		PrimaryObject inputData = input.getData();
		data = inputData.getAdapter(INoticeProvider.class);
		esp = new WorkEventNoticeSettingPanel(parent,
				data instanceof WorkEventNoticeTemplate);
		esp.setInput(data);
		esp.addValueChangeListener(this);
		return esp;
	}

	@Override
	public void commit(boolean onSave) {
		if (onSave) {
			setDirty(false);
		}
	}

	@Override
	public void setFocus() {

	}

	@Override
	public void valueChanged(String key, Object oldValue, Object newValue) {
		setDirty(true);
	}

}
